#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int wiggleMaxLength(vector<int>& nums) {
	int n=nums.size();
	if (n < 2)
		return n;
	int ret = 0, left = 0;
	for (int i = 0; i < n - 1; i++)
	{
		int right = nums[i+1] - nums[i];
		if (right == 0)
			continue;
		if (left * right <=0)
			ret++;
		left = right;
	}
	return ret + 1;
}
int lengthOfLIS(vector<int>& nums) {
	vector<int> v;
	v.push_back(nums[0]);
	for (auto& e : nums)
	{
		if (e > v.back())
			v.push_back(e);
		else
		{
			int left = 0, right = nums.size() - 1;
			while (left < right)
			{
				int mid = left + (right - left) / 2;
				if (nums[mid] > e)
					right = mid - 1;
				else if (nums[mid] < e)
					left = mid + 1;
			}
			v[left] = e;
		}
	}
	return v.size();
}
bool increasingTriplet(vector<int>& nums) {
	int n = nums.size();
	if (n < 3)
		return false;
	int a = nums[0], b = INT_MAX;
	for (auto& e : nums)
	{
		if (e > b)
			return true;
		else
		{
			if (e < a)
				a = e;
			else if (e < b)
				b = e;
		}
	}
	return false;
}
int findLengthOfLCIS(vector<int>& nums) {
	int n = nums.size();
	if (n < 2)
		return n;
	int left = 0, right = 1,ret=0;
	while (right<n)
	{
		while (right<n&&nums[right] > nums[right - 1])
			right++;
		ret = max(ret,right - left);
		left = right++;
	}
	return ret;
}
int maxProfit(vector<int>& prices) {
	int n = prices.size();
	int i = 0, j = 0,ret=0;
	while (j < n)
	{
		while (j + 1 < n && prices[j + 1] > prices[j])
			j++;
		ret += prices[j] - prices[i];
		i = ++j;
	}
	return ret;
}
int maxProfit(vector<int>& prices) {
	int n = prices.size();
	int ret = 0, prevmin = INT_MAX;
	for (int i = 0; i < n; i++)
	{
		ret = max(ret, prices[i] - prevmin);
		prevmin = min(prevmin, prices[i]);
	}
	return ret;
}
int largestSumAfterKNegations(vector<int>& nums, int k) {
	int count = 0,sum = 0,absmin=INT_MAX;
	for (auto& e : nums)
	{
		if (e < 0)
			count++;
		else
			sum += e;
		absmin = min(absmin, abs(e));
	}
	sort(nums.begin(), nums.end());
	if (k <= count)
	{
		for (int i = 0; i < k; i++)
			sum += (-nums[i]);
		for (int i = k; i < count; i++)
			sum += nums[i];
	}
	else
	{
		for (int i = 0; i < count; i++)
			sum += (-nums[i]);
		k -= count;
		if (k % 2)
			sum -= 2 * absmin;
	}
	return sum;
}
int main()
{
	vector<int> nums = { 1,3,5,7,4 };
	findLengthOfLCIS(nums);
	return 0;
}